﻿import time
import itchat
from itchat.content import *

@itchat.msg_register([TEXT])
def simple_reply(msg):
    msg_from = (itchat.search_friends(userName=msg['FromUserName']))["NickName"]
    msg_to = (itchat.search_friends(userName=msg['ToUserName']))["NickName"]
    print('【' + str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) + '】' + msg_from +'>>'+msg_to+':' + msg['Content'])
    f = open('/root/ftp/history.txt', 'a')
    f.write('【' + str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) + '】' + msg_from +'>>'+msg_to+':' + msg['Content'] + '\r\n')
    f.close()
    if msg['User']['NickName']=='未曾只因':
        users = itchat.search_friends(name='尹飞')
        userName = users[0]
        replycontent=msg['Content']
        itchat.send_msg(replycontent,userName['UserName'])
    else:
        # users = itchat.search_friends(name='filehelper')
        # userName = users[0]
        # itchat.send_msg(msg['Content'], userName['UserName'])
        itchat.send_msg(msg['Content'],toUserName='filehelper')

itchat.auto_login(enableCmdQR=2)
itchat.run()
